package com.sinopec.android.util;

import com.sinopec.android.constant.ConfigAttrs;
import com.sinopec.android.constant.Constants;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;

/**
 * 程序退出
 * @author huangyu
 *
 */
public class ExitUtil {

	public static void openDialog(final Context context){
		AlertDialog.Builder builder = new Builder(context);
		builder.setTitle("退出应用");
		builder.setMessage("您确定要退出吗？");
		builder.setPositiveButton("确定", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				//注销用户，删除SharePreferences的用户信息
				SharePreferencesUtil.clearLoginUserName(context);
//				SharePreferencesUtil.clearLastLoginAccount(context, ConfigAttrs.LAST_LOGIN_ACCOUNT);
				SharePreferencesUtil.clearLastLoginAccount(context, ConfigAttrs.LAST_LOGIN_PWD);
				//关闭所有actiivity
				if(Constants.activityList!=null&&Constants.activityList.size()>0){
					for(int i=0;i<Constants.activityList.size();i++){
						Constants.activityList.get(i).finish();
					}
				}
				
			}
		});
		builder.setNegativeButton("取消", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
		builder.show();
		
		
	}
	
}
